package com.lagou.homework3_1;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * 把数字封装到对象，作为map输出的key
 */
public class Number implements WritableComparable<Number> {
    private Integer num;

    // 自定义排序方法，按照数据大小 升序
    @Override
    public int compareTo(Number number) {
        return this.num - number.getNum();
    }
    // 序列化方法
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(num);
    }
    // 反序列化方法
    @Override
    public void readFields(DataInput in) throws IOException {
        this.num = in.readInt();
    }
    // 无参构造
    public Number() {
    }

    public Number(Integer num) {
        this.num = num;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }
}
